package com.ntv.presentation.spring.web.news;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.ntv.common.NewsType;
import com.ntv.domain.INews;
import com.ntv.service.news.INewsAppService;

@Controller
@RequestMapping("/newshome.html")
public class NewsHomeController
{
	
	private static final Logger logger = Logger.getLogger(NewsHomeController.class);
	
	@Autowired
	private INewsAppService newsAppService;
	
	public void setNewsAppService(INewsAppService newsAppService) {
		this.newsAppService = newsAppService;
	}

	
	 	@RequestMapping(method = RequestMethod.GET)
	    public ModelAndView setupForm(@RequestParam("id") int id, ModelMap model) throws Exception {
	 		INews news = newsAppService.getNewsByTypeAndNewsId(null, new Long(id));
			List<INews> nationalNewsList = newsAppService.getNataionNewsList();
			Map model1 = new HashMap();
			model1.put("news", news);		
			model1.put(NewsType.NATIONAL.getDescription(), nationalNewsList);
			ModelAndView mav = new ModelAndView("home.news", model1);
			return mav;
	    }
	 
	 /* @Override 
	  protected Object formBackingObject(HttpServletRequest request) {

		String id = (String)request.getParameter("id");
		
		INews news = newsAppService.getNewsByTypeAndNewsId(null, new Long(id));
		List<INews> nationalNewsList = newsAppService.getNataionNewsList();
		Map model = new HashMap();
		model.put("news", news);		
		model.put(NewsType.NATIONAL.getDescription(), nationalNewsList);
		ModelAndView mav = new ModelAndView("home.news", model);
		return mav;
	}*/
}
